﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QLVT.Config;
using QLVT.Entity;

namespace QLVT.DAO
{
    class ChiTietChiTietPhieuNhapDAO:DAOBase
    {
        public DataSet GetAll()
        {
            return Select("select * from ChiTietPhieuNhap");
        }

        public ChiTietPhieuNhap GetById(String sophieuid)
        {
            ChiTietPhieuNhap sophieu = null;
            SqlConnection conn = null;
            try
            {
                conn = Config.Config.getConnection();
                conn.Open();
                SqlCommand commnad = new SqlCommand("select * from ChiTietPhieuNhap where sophieu = '" + sophieuid + "'", conn);
                SqlDataReader dataReader = commnad.ExecuteReader();
                if (dataReader.Read())
                {
                    sophieu = new ChiTietPhieuNhap();
                    sophieu.Sophieu = dataReader.GetString(0);
                    sophieu.Mahang = dataReader.GetString(1);
                    sophieu.Soluong = dataReader.GetInt32(2);
                    sophieu.Dongia = dataReader.GetFloat(3);
                    return sophieu;
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                conn.Close();
               
            }
            return sophieu;
        }

        public bool DeleteById(String sophieu)
        {
            return Update("delete from ChiTietPhieuNhap where sophieu = '" + sophieu + "'");
        }

        public bool UpdateById(ChiTietPhieuNhap sophieu)
        {
            String sql = "update ChiTietPhieuNhap "
                 + "set ngaynhap = '" + sophieu.Soluong + "'"
                 + ", manv = '" + sophieu.Dongia + "'"
                 + " where sophieu = " + sophieu.Sophieu + "'";

            return Update(sql);
        }
    }
}
